import { Http } from '@angular/http';
import { ServiceBase } from './serviceBase';
import { Injectable } from '@angular/core';

@Injectable()
export class PrintService extends ServiceBase {
    constructor(protected http: Http) {
        super();
        console.log("print实例化-------------------", new Date())
        this.getAdsServerInfo();
    }
    private adsAddress: string = "localhost";

    set adsServer(adsServer) {
        let adsServerStr = JSON.stringify(adsServer);
        localStorage.setItem("adsServer", adsServerStr);
    }

    get adsServer() {
        let adsServerStr = localStorage.getItem("adsServer");
        if (!adsServerStr) {
            return null;
        }
        return JSON.parse(adsServerStr);
    }
    /**
     * 获取ads服务的信息
     */
    async getAdsServerInfo() {
        let result = await this.Get("about", this.adsAddress, this.SSL ? 8865 : 8866);
        if (this.SSL) {
            result.url = result.url.replace("http", "https");
            result.url = result.url.replace("8866", "8865");
        }
        if (result) {
            this.adsServer = result;
        }
    }
}